<template>
  <div>
    <table-ext :columns="columns" :searchForm="searchForm" :config="config" ref="tableExt">
    </table-ext>
  </div>
</template>
<script>
  import TableExt from '@/components/common/table-ext/table-ext.vue';
  import TableIcon from '@/components/common/table-ext/table-icon';
  export default {
    // 引入自定义表格组件
    components:{
      'table-ext': TableExt
    },
    data() {
      return {
        config:{ // 页面共通配置
          title: '物料打样', //页面标题
          isPage: true, //是否分页
          isNo: true, //是否显示序号
          selection: false, //是否显示复选框
          crudMapping:{ // CRUD方法
            query:{
              url: this.lib.config.host.vendorDlv + "/vendormgt/npc/npcTask/query",
              data:{'vendorId': this.$route.query.id}
            }
          }
        },
        // 查询表单配置
        searchForm:[{
          label: '采购组织:',
          key: 'purOrgId',
          type: 'select',
          dict: {
            url: this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/' + this.getCurrUserId(),
            method: 'get',
            label: 'purOrgName',
            value: 'id'
          }
        },{
          label: '采购组:',
          key: 'groupId',
          type: 'select',
          dict: {
            url: this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/{purOrgId}',
            method: 'post',
            label: 'purGroupName',
            value: 'id'
          }
        },{
          label: '工厂:',
          key: 'factoryId',
          type: 'select',
          dict: {
            url:  this.lib.config.host.masterData + '/system/factoryMgt/factorys/getFactoryByPurId/{purOrgId}',
            method: 'post',
            label: 'factoryName',
            value: 'factoryId'
          }
        },{
          label: '任务编码:',
          key: 'taskCode',
          type: 'input'
        },{
          label: '任务名称:',
          key: 'taskName',
          type: 'input'
        },{
          label: '发布状态:',
          key: 'publishStatus',
          type: 'select',
          dict: [{
            key: '0',
            value: '未发布'
          },{
            key: '1',
            value: '已发布'
          }]
        },{
          label: '审核状态:',
          key: 'checkStatus',
          type: 'select',
          dict: [{
            value: '0',
            label: '未开始'
          },{
            value: '1',
            label: '通过'
          },{
            value: '3',
            label: '待审核'
          },{
            value: '-1',
            label: '驳回'
          }]
        },{
          label: '确认状态:',
          key: 'confirmStatus',
          type: 'select',
          dict: [{
            key: '0',
            value: '未确认'
          },{
            key: '1',
            value: '已确认'
          },{
            key: '2',
            value: '部分确认'
          }]
        },{
          label: '是否含驳回项:',
          key: 'existRefuse',
          type: 'select',
          dict: [{
            key: '0',
            value: '否'
          },{
            key: '1',
            value: '是'
          }]
        },{
          label: '打样状态:',
          key: 'completeStatus',
          type: 'select',
          dict: [{
            key: '0',
            value: '未完成'
          },{
            key: '1',
            value: '已完成'
          },{
            key: '2',
            value: '部分完成'
          }]
        }],
        // 表格列定义
        columns:[{
          label: '采购组织',
          key: 'purOrgName',
          align: 'center'
        },{
          label: '采购组',
          key: 'purGroupName',
          align: 'center'
        },{
          label: '工厂',
          key: 'factoryName',
          align: 'center'
        },{
          label: '任务编码',
          key: 'taskCode',
          align: 'center',
        },{
          label: '任务名称',
          key: 'taskName',
          align: 'center'
        },{
          label: '发布状态',
          key: 'publishStatus',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.publishStatus,
                titles: [{status:0,title:'发布'},{status:1,title:'已发布'}]
            }});
          }
        },{
          label: '审核状态',
          key: 'checkStatus',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.checkStatus,
                titles: [{status:0,title:'未审核'},{status:1,title:'已审核'},{status:3,title:'待审核'}]
            }});
          }
        },{
          label: '确认状态',
          key: 'confirmStatus',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.confirmStatus,
                titles: [{status:0,title:'未确认'},{status:1,title:'已确认'}]
            }});
          }
        },{
          label: '是否含驳回项',
          key: 'existRefuse',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.existRefuse,
                titles: [{status:0,title:'否'},{status:1,title:'是'}]
            }});
          }
        },{
          label: '打样状态',
          key: 'completeStatus',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.completeStatus,
                titles: [{status:0,title:'未完成'},{status:1,title:'已完成'}]
            }});
          }
        }]
      };
    },
    created(){

    },
    mounted() {
       //this.initData();
    },
    methods: {
      initData(){
        // 获取采购组织
        this.getSelectData('get', this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/' + this.getCurrUserId(), {}, 'id', 'purOrgName').then((data)=>{
            this.purOrgOptions = data;
        });
      },
      // 采购组织在改变的时候查询采购组
      handleChange(value) {
        // 获取srm采购组
        this.getSelectData('post', this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/' + value, {}, 'id', 'purGroupName').then((data)=>{
            this.relationPurGroup = data;
        });
        // 获取采购组织对应的工厂
        this.getSelectData('post', this.lib.config.host.masterData + '/system/factoryMgt/factorys/getFactoryByPurId/' + value, {}, 'id', 'factoryName').then((data)=>{
            this.relationFactory = data;
        });
      }
    }
  }
</script>